package com.tianluo.tianluobookstore.controller;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class JwtSecretGeneratorTest {

    public static void main(String[] args) {
        try {
            // 生成一个256位的HMAC-SHA256密钥
            KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacSHA256");
            keyGenerator.init(256);
            SecretKey secretKey = keyGenerator.generateKey();

            // 将密钥转换为Base64编码的字符串，以便存储或传输
            String base64EncodedSecret = Base64.getEncoder().encodeToString(secretKey.getEncoded());
            System.out.println("Generated JWT Secret (Base64 Encoded): " + base64EncodedSecret);

            System.out.println(secretKey.toString());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            // 处理异常，例如记录日志或抛出运行时异常
        }
    }


}
